#include "bullet.h"
#include<QtMath>

Bullet::Bullet()
{
    //初始化坐标
    m_x=100;
    m_y=100;
    //初始化图片
    m_Bullet.load(HERO1_BULLET);

    //子弹状态
    m_Free=1;//默认空闲

    //子弹速度
    m_Speed=BULLET1_SPEED;

    //子弹边框
    m_rect.setWidth(25);
    m_rect.setHeight(50);
    m_rect.moveTo(m_x+53,m_y+10);
}
//更新子弹坐标
void Bullet::updatePosition()
{
    //空闲状态下的子弹，不需要计算坐标
    if(m_Free==1)
    {
        return;
    }
    //子弹向上移动
    else
    {

         m_y-=m_Speed;;
         //m_x+=150*sin(20000*m_y);

        m_rect.moveTo(m_x+53,m_y+10);
        if(m_y<=(-m_rect.height()))
        {
            m_Free=1;
        }
    }
}

void Bullet::updatePosition2()
{
    //空闲状态下的子弹，不需要计算坐标
    if(m_Free==1)
    {
        t=GAME_HEIGHT;
        return;
    }
    //子弹向上移动
    else
    {
         m_y-=12;
         t-=20;
         m_x+=550*sin(5000*t-4000);

        m_rect.moveTo(m_x+53,m_y+10);
        if(m_y<=(-m_rect.height()))
        {
            m_Free=1;
            t=GAME_HEIGHT;
        }


    }
}

void Bullet::updatePosition3()
{

    //空闲状态下的子弹，不需要计算坐标
    if(m_Free==1)
    {
        t2=GAME_HEIGHT;
        return;
    }
    //子弹向上移动
    else
    {
         m_y-=10;
         t2-=20;
         m_x+=5*(sin(5000*t2-4000)*sin(5000*t2-4000));

        m_rect.moveTo(m_x+53,m_y+10);
        if(m_y<=(-m_rect.height()))
        {
            m_Free=1;
            t2=GAME_HEIGHT;
        }


    }
}

void Bullet::updatePosition4()
{

    //空闲状态下的子弹，不需要计算坐标
    if(m_Free==1)
    {
        t3=GAME_HEIGHT;
        return;
    }
    //子弹向上移动
    else
    {
         m_y-=10;
         t3-=20;
         m_x-=5  *(sin(5000*t3-4000)*sin(5000*t3-4000));

        m_rect.moveTo(m_x+53,m_y+10);
        if(m_y<=(-m_rect.height()))
        {
            m_Free=1;
            t3=GAME_HEIGHT;
        }


    }
}
